-- MathPad can plot an expression by using the "plot" command.
Xmin=-10; Xmax=10
plot 5*X
-- The independent variable "X" (upper case) is stepped between "Xmin" and "Xmax" with a resolution of "Xsteps" (default Xsteps=100). Various aspects of the plot can be controlled by special variables. None of the special variables are required but usually at least the range of X values is specified.
-- A info line at the bottom of the plot window shows the lowest and highest Y values ("Ylo" and "Yhi") calculated during the plot.
-- The variables "Ymin" and "Ymax" can be used to set the Y axis limits. If Ymin and/or Ymax are not specified MathPad will auto-range based on Ylo and Yhi.
-- Evaluation can be stopped by typing Command-period.
-- Multiple traces can be plotted simply by adding plot statements. All traces use the same values of "Xmin", "Xmax", "Xsteps", "Ymin" and "Ymax". The "Ylo" and "Yhi" values apply over all traces.
f(t) = t^3/10 - 5*t
plot f(X)
plot f(2*X)/10
-- Clicking the mouse on the plot will show the trace number and the X,Y value of the plotted point nearest to the click.
-- A plot can be copied to the clipboard as a PICT. The "Copy Plot" menu items are enabled when the plot window is in front. The clipboard image will be the same size as the current plot window size. The "Copy Plot at 4X" command scales the image up to provide a higher resolution image for applications that can import and re-size PICTs.
-- A PICT can be pasted into the plot to provide a background. The PICT will be sized to fit inside the axis.
-- A plot can be printed. For printing, the plot is re-sized to the page regardless of the current plot window size. Printing is done at the highest printer resolution so it may be useful to increase Xsteps for a smoother plot. The Options... dialog controls whether the info line is included.
-- The zoom box sets the window to the current printer page aspect. This allows a sort of print preview so you can position labels appropriately for printout.
-- The Options... dialog allows adding grid lines.
-- Axis ticks can be controlled by the special variables Xdiv and Ydiv. If these variables are used they override the automatic axis. They specify the distance between labeled ticks in data units. The axis label format still assumes that "nice" divs (at most 2 digits of precision) will be used. This means that a div like .2 or .25 will work but a div of .234 will have rounded tick labels. If there are too many or too few divisions the axis will revert to automatic divisions.
Xdiv=2
-------- Adding labels
-- Arbitrary text labels may be pasted into the plot window. Selecting "Paste Label" from the Edit menu will paste text from the clipboard into the upper left corner of the plot. Command-V will paste the label at the current mouse position if it is in the plot window.
-- "label" statements can be used to put a line from the text window onto the plot. The text following "label" is evaluated normally. This allows labels that will automatically update when the text is reevaluated.
label f(5):-12.500
-- Labels can be moved by dragging with the mouse.
-- Labels can be deleted by dragging them off the plot.
-- Special variables Xlabel, Ylabel and Title allow adding labels at preassigned locations. The plot size is adjusted to make room for these labels if they are present. These labels are not movable.
Title = "Example Plot"
Ylabel = "f(X)"
------- Log axes
-- The Options... dialog can be used to set the log axis option for a plot. See the file "Log Axes" for more details.
------- Multiple Plots
-- The "newaxis" command can be used to put more than one set of axes on a page. The plot control variables can be changed following a "newaxis". They must be changed with an := assignment. All changes to plot control variables must appear before the first plot statement for the new axis.
newaxis
Xmin:=-1:;
Ymin:=-1:; Ymax:=1:;
Ylabel:="arrays":
Xlabel:="X axis":
-- Any plot control variables that are not assigned will keep their previous values. A variable can be set back to undefined by assigning "?"
Xmax:=?:; -- enable auto-ranging
-- Special variables Xlogaxis, Xshowgrid, Xticklabels, Ylogaxis, Yshowgrid, Yticklabels, Zlogaxis, Zshowbar allow changing axis options for each strip.
-- The special variable Ystrips can be used to preset the number of different axes that will be put on the plot. The use of Ystrips is optional. It can be used to prevent extra redrawing of the plot window.
Ystrips = 2
-- Ystrips can either be set to the number of equal height strips (Ex. Ystrips=2) or it can be set to an array where the elements give a relative height for each strip. Ystrips = {1.7,1,1} specifies 3 strips, the 1st strip is given 70% more height.
------- Plotting Arrays
-- The plot command can also plot points from 1D or 2D arrays.
-- Arrays can be given in 5 forms:
-- parametric functions {fx(X),fy(X)} X steps 0 to 1.0
-- array of y values {y1,y2,y3...}
-- array of y functions {fy1(X),fy2(X),fy3(X),...}
-- array of x,y pairs {{x1,y1},{x2,y2},{x3,y3},...}
-- a pair of arrays {{x1,x2,...},{y1,y2,...}}
-- For 1D {y1,y2,y3...} the element values are used for y. The points are plotted evenly spaced along the current X axis.
-- For 2D arrays, both x and y are taken from the array
-- A 2 by 2 array is treated as {{x1,x2},{y1,y2}}
-- A 2D array with more than 2 elements is assumed to be a list of {x,y} pairs. If they are not pairs, values after the first 2 will be ignored. {{x,y,...},{x,y,...},{x,y,...}}
-- When plotting x,y points, if Xmin and/or Xmax are not specified they will be auto-ranged. When plotting a mix of arrays and functions, the array should be plotted first to take advantage of X auto-ranging.
------ Parametric equations
-- For {fx(X),fy(X)} X is stepped from 0 to 1.0 and the resulting points are plotted in the range Xmin to Xmax. This can be used for parametric equations:
deg=X*360; Xsteps=36 -- run deg from 0 to 360 in 10° steps
x(angle)=cos(angle)
y(angle)=sin(angle)
plot {x(deg),y(deg)}
-- The "plotline" command can be used to connect the points for any array plot. For {x,y} plots the points are connected in the order that they appear in the array. An undefined point causes the pen to be lifted. The pen is put down when the next defined point is found. If a single defined point is surrounded by undefineds it will not be plotted.
plotline {x(deg),y(deg)}*.7
----- Plotting a family of curves
-- An array of 3 or more functions will be plotted as multiple traces. X is stepped from Xmin to Xmax for each function.
~ (Copy this example to a new document to try it.)
f(x)[i] = i/(x+i) dim[10]
Xmin=0; Xmax=20
plot f(X)
~
-------- Plotting surfaces
-- 2D arrays representing surfaces can be displayed with the "image" command. Each array element is displayed as a tile filled with a color corresponding to its value. See the file "Images" for details.
Zmin=0; Zmax=30; Zlabel="image"
array[ix,iy] = (ix-5)^2 + (iy-5)^2 dim[9,9]
image array
-- The XFun "viewsurf" can be used to show a 3D projection of a surface. See the file "3D Plotting" for more info.
-------- Summary of special variables used for plotting
~
X independent variable
Xmin=n minimum value for X axis
Xmax=n maximum value for X axis
Xsteps=n resolution for stepping X values
Xdiv=n distance between axis ticks
Xlabel="label" add X axis label
Xlogaxis=on use log X axis
Xshowgrid=on show vertical grid lines
Xticklabels=off suppress X axis numeric tick labels
Ymin=n minimum value for Y axis
Ymax=n maximum value for Y axis
Ydiv=n distance between axis ticks
Ylabel="label" add Y axis label
Ylogaxis=on use log Y axis
Yshowgrid=on show horizontal grid lines
Yticklabels=off suppress Y axis numeric tick labels
Zmin=n image data minimum
Zmax=n image data maximum
Zlabel="label" add Z axis label
Zlogaxis=on log image data
Zshowbar=off suppress Z color bar
Ystrips=n preset the number of different axes
Ystrips={1,2,…} preset relative height of each strip